package com.kkb.controller;

import com.kkb.pojo.Param;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/params")   //   /params/gotoParams.do?id=1222
public class ParamsController {
    @GetMapping("/gotoParams1")
    public ModelAndView gotoGetParams1(ModelAndView modelAndView, HttpServletRequest request, HttpServletResponse response, HttpSession session){
        // 封装数据
        String id = request.getParameter("id");
        modelAndView.addObject("id", id);
        // 指定页面
        modelAndView.setViewName("params");
        return modelAndView;
    }
    @PostMapping("/gotoParams1")
    public ModelAndView gotoPostParams1(ModelAndView modelAndView, HttpServletRequest request, HttpServletResponse response, HttpSession session){
        // 封装数据
        String number = request.getParameter("number");
        modelAndView.addObject("postNumber", number);
        // 指定页面
        modelAndView.setViewName("params");
        return modelAndView;
    }

    @GetMapping("/gotoParams2")
    public ModelAndView gotoGetParams2(ModelAndView modelAndView, @RequestParam("id") Integer ids){
        modelAndView.addObject("id", ids);
        modelAndView.setViewName("params");
        return modelAndView;
    }

    @PostMapping("/gotoParams2")
    public ModelAndView gotoPostParams2(ModelAndView modelAndView, Integer number, String goods){
        modelAndView.addObject("postNumber", number);
        modelAndView.addObject("goods", goods);
        modelAndView.setViewName("params");
        return modelAndView;
    }
    @GetMapping("/gotoParams3")
    public ModelAndView gotoGetParams3(ModelAndView modelAndView, Param param){
        modelAndView.addObject("param", param);
        modelAndView.setViewName("params");
        System.out.println(param);
        return modelAndView;
    }

    @PostMapping("/gotoParams3")
    public ModelAndView gotoPostParams3(ModelAndView modelAndView, Param param){
        modelAndView.addObject("param", param);
        modelAndView.setViewName("params");
        System.out.println(param);
        return modelAndView;
    }
}
